﻿using System;

namespace Cpu6502.Opcodes
{
    /// <summary>
    /// STX $AAAA - Store Register X Absolute Mode
    /// Stores Register X in memory address
    /// </summary>
    class STX_A : Opcode
    {
        public STX_A()
        {
            this.CpuCycles = 4;
            this.AddressType = CPU.AddressType.Absolute;
        }

        public override void Execute()
        {
            CPU.Memory[base.Argument] = CPU.Registers.X;
        }
    }

    
    /// <summary>
    /// STX $AA - Store Register X Zeropage Mode
    /// Stores Register X in memory address
    /// </summary>
    class STX_ZP : Opcode
    {
        public STX_ZP()
        {
            this.CpuCycles = 3;
            this.AddressType = CPU.AddressType.ZeroPage;
        }

        public override void Execute()
        {
            CPU.Memory
                [
                    MemoryHelper.GetAddress
                    (base.Argument, CPU.AddressType.ZeroPage)
                ] = CPU.Registers.X;
        }
    }

    /// <summary>
    /// STX $AA, Y - Store Register X Zeropage Y Mode
    /// Stores Register X in memory address
    /// </summary>
    class STX_ZP_Y : Opcode
    {
        public STX_ZP_Y()
        {
            this.CpuCycles = 4;
            this.AddressType = CPU.AddressType.ZeroPageIndexedY;
        }

        public override void Execute()
        {
            CPU.Memory
                [
                    MemoryHelper.GetAddress
                    (base.Argument, CPU.AddressType.ZeroPageIndexedY)
                ] = CPU.Registers.X;
        }
    }
}
